#include "CommonArgs.h"
#include "clang/Basic/TargetID.h"
#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Distro.h"
#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/InputInfo.h"
#include "clang/Driver/Options.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/Host.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/VirtualFileSystem.h"
ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
/*StrictChecking=*/true);
+ Distro Dist(D.getVFS(), llvm::Triple(llvm::sys::getProcessTriple()));
+ if (Dist.IsDebian() || Dist.IsRedhat()) {
+ ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
+ /*StrictChecking=*/true);
+ ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
+ /*StrictChecking=*/true);
+ }
+
DoPrintROCmSearchDirs();
return ROCmSearchDirs;
}
llvm::sys::path::append(IncludePath, "include");
LibPath = InstallPath;
llvm::sys::path::append(LibPath, "lib");
-
- llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
- FS.getBufferForFile(BinPath + "/.hipVersion");
- if (!VersionFile && Candidate.StrictChecking)
- continue;
-
- if (HIPVersionArg.empty() && VersionFile)
- if (parseHIPVersionFile((*VersionFile)->getBuffer()))
+ SharePath = InstallPath;
+ llvm::sys::path::append(SharePath, "share");
+
+ // If HIP version file can be found and parsed, use HIP version from there.
+ for (const auto &VersionFilePath :
+ {std::string(SharePath) + "/hip/version",
+ std::string(BinPath) + "/.hipVersion"}) {
+ llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
+ FS.getBufferForFile(VersionFilePath);
+ if (!VersionFile)
continue;
+ if (HIPVersionArg.empty() && VersionFile)
+ if (parseHIPVersionFile((*VersionFile)->getBuffer()))
+ continue;
- HasHIPRuntime = true;
- return;
+ HasHIPRuntime = true;
+ return;
+ }
+ // Otherwise, if -rocm-path is specified (no strict checking), use the
+ // default HIP version or specified by --hip-version.
+ if (!Candidate.StrictChecking) {
+ HasHIPRuntime = true;
+ return;
+ }
}
HasHIPRuntime = false;
}
// RUN: -target amdgcn-amd-amdhsa \
// RUN: | FileCheck -check-prefixes=FOUND %s
+// RUN: rm -rf %t/Inputs
+// RUN: mkdir -p %t/Inputs
+// RUN: cp -r %S/Inputs/rocm %t/Inputs
+// RUN: mkdir -p %t/Inputs/rocm/share/hip
+// RUN: mv %t/Inputs/rocm/bin/.hipVersion %t/Inputs/rocm/share/hip/version
+// RUN: %clang -v --rocm-path=%t/Inputs/rocm 2>&1 \
+// RUN: | FileCheck -check-prefixes=FOUND %s
+
// FOUND: Found HIP installation: {{.*Inputs.*rocm}}, version 3.6.20214-a2917cd
// When --rocm-path is set and .hipVersion is not found, use default version